<%--
  Created by IntelliJ IDEA.
  User: 13976
  Date: 2019/10/5
  Time: 19:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <base href="<%=basepath %>"/>
    <link rel="stylesheet" href="static/layui/css/layui.css">
</head>
<body>
<div style="margin: 40px">
    <h2>新增app信息</h2>
</div>
<form class="layui-form" id="form-user-add" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">软件名称</label>
        <div class="layui-input-inline">
            <input type="text" name="softwarename" required  lay-verify="required" placeholder="请输入软件名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">APK名称</label>
        <div class="layui-input-inline">
            <input type="text" name="apkname" required lay-verify="required" placeholder="请输入APK名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">支持ORM</label>
        <div class="layui-input-inline">
            <input type="text" name="supportrom" required lay-verify="required" placeholder="请输入支持ORM" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">界面语言</label>
        <div class="layui-input-inline">
            <input type="text" name="interfacelanguage" required lay-verify="required" placeholder="请输入界面语言" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">软件大小</label>
        <div class="layui-input-inline">
            <input type="text" name="softwaresize" required lay-verify="required" placeholder="请输入软件大小" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">下载次数</label>
        <div class="layui-input-inline">
            <input type="text" name="downloads" required lay-verify="required" placeholder="请输入下载次数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属平台</label>
        <div class="layui-input-inline">
            <select name="flatformid" id="ping" required>

            </select>
        </div>
    </div>
   <div class="layui-form-item">
        <label class="layui-form-label">一级分类</label>
        <div class="layui-input-inline">
            <select name="categoryleve1" id="yi" class="layui-select" lay-filter='rep'>
                <option value="1">待审核</option>
                <option value="4">待审核</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">二级分类</label>
        <div class="layui-input-inline">
            <select name="categoryleve2" id="er" class="layui-select" lay-filter='rep2'>

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">三级分类</label>
        <div class="layui-input-inline">
            <select name="categoryleve3" id="san" >

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">APP状态</label>
        <div class="layui-input-inline">
            <select name="status" id="status" disabled="disabled">
                <option value="12">新增</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">版本简介</label>
        <div class="layui-input-block">
            <textarea name="appinfo" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <input class="layui-input"  name="logolocpath" autocomplete="off" id="photo"  />
        <label class="layui-form-label">LOGO图片</label>
        <div class="layui-input-inline" style="width:300px">
            <button class="magicalcoder-layupload layui-btn" type="button" id="photobtn">上传图片</button>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                预览图：
                <div class="layui-upload-list" id="photodiv" ></div>
            </blockquote>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo" >立即提交</button>
            <button class="layui-btn"  lay-filter="formDemo" onclick="parent.window.location.reload()">返回</button>
        </div>
    </div>
</form>
<script src="static/js/jquery.min.js"></script>
<script src="static/ruoyi/ry-ui.js"></script>

<script src="static/layui/layui.all.js"></script>
<script src="static/validate/jquery.validate.min.js"></script>
<script src="static/validate/messages_zh.min.js"></script>
<script src="static/validate/jquery.validate.extend.js"></script>
<script src="static/layui/lay/modules/layer.js"></script>

<script type="text/javascript">
    //init method one
    layui.use(['upload','form','laydate','layer'], function (upload,form,laydate,layer) {
        var $ = layui.jquery;
        var d=$("#yi").val();
        $("#yi").empty();

        $.ajax({url:"xia/zhuang",success:function(result){
                var arr = result;
                $("#ping").empty();
                var str = "";
                str +="<option value='0'>请选择</option>"
                for (var i = 0; i < arr.length; i++) {
                    str += "<option value='"+arr[i].id +"'>"+ arr[i].valuename+"</option>";
                }
                $("#ping").append($(str));

            }});

        $.ajax({url:"xia/one",success:function(result){
                var arr = result;
                $("#yi").empty();

                var str = "";
                str +="<option value='0'>请选择</option>"
                for (var i = 0; i < arr.length; i++) {
                    str += "<option value='"+arr[i].id +"'>"+ arr[i].categoryname+"</option>";
                }
                $("#yi").append($(str));
                form.render("select");
            }});



        form.on('select(rep)', function(data){
            var yi=$("#yi").val();

            if(yi==0){
                $("#er").empty();
                $("#san").empty();
            }else{
                $.ajax({url:"xia/two",
                    data:{two: yi},
                    success:function(result){
                        var arr = result;
                        $("#er").empty();
                        var str = "";

                        str +="<option value='0'>请选择</option>"
                        for (var i = 0; i < arr.length; i++) {
                            str += "<option value='"+arr[i].id +"'>"+ arr[i].categoryname+"</option>";
                        }
                        $("#er").append($(str));
                        form.render("select");
                    }});
            }
        });


        form.on('select(rep2)', function(data){
            var yi=$("#er").val();
            if(yi==0){

                $("#san").empty();
            }else{
                var layer = layui.layer;
                $.ajax({url:"xia/three",
                    data:{three: yi},
                    success:function(result){
                        var arr = result;
                        $("#san").empty();
                        var str = "";
                        str +="<option value='0'>请选择</option>"
                        for (var i = 0; i < arr.length; i++) {
                            str += "<option value='"+arr[i].id +"'>"+ arr[i].categoryname+"</option>";
                        }
                        $("#san").append($(str));
                        form.render("select");
                    }});
            }
        });

        upload.render({
            elem: '#photobtn'
            ,url: 'dev/upload'
            ,size: 24*5
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#photodiv').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                });
            }
            ,done: function(res){
                $("#photo").val(res.msg);
            }
        });

        form.on('submit(formDemo)',function (data) {
            if($("#yi").val()=="0"||$("#er").val()=="0"||$("#san").val()=="0"||$("#ping").val()=="0"){
                layer.msg("请选择下拉列表内容")
            }
            $.post("app/addApp",data.field,function (res) {
                console.log(res)

                layer.msg('添加成功', {
                    index:10000,
                    icon: res,
                    time: 3000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){
                    //刷新父窗口
                    parent.window.location.reload();
                });

            })

            return false;
        })


    });


layui.use(['upload','form','laydate'], function (upload,form,laydate) {
    var $ = layui.jquery;
    laydate.render({
        elem: '#admissionDate' //指定元素
        ,type: 'datetime'
    });


    //多图片上传

});
</script>

</body>
</html>
